package com.bxs.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * 时间工具类
 */
public class TimeUtils {
    // 时间段取整
    public static Date generateIntervalTime(Date date, int interval){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        // 获取当前时间分钟
        int minute = calendar.get(Calendar.MINUTE);
        int minute2 = ((minute + interval)/interval - 1) * interval;   // 向下取整减一再乘上间隔
        calendar.set(Calendar.MINUTE, minute2);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    public static void main(String[] args) {
        Date date = generateIntervalTime(new Date(), 10);
    }
}
